<?php
//Code by Nguyen Quoc Cuong
//Mail: cuongctim@yahoo.com.vn
require_once 'models/models_mathang.php';
$mod = $_GET['mod'];
$obmh = new models_mathang();
require_once 'models/models_loaihang.php'; //goi trang model loai hang
$oblh = new models_loaihang(); //khoi tao doi tuong loai hang
switch ($mod){
	case 'mathang':{
		$obmh = new models_mathang();
		$data['list'] = $obmh->listMatHang();
		$data['listlh'] = $oblh->listloaihang();
		require 'views/admin/mathang/index.php';
		break;
	}
	case 'addmathang':{
		if($_POST){
			if (isset($_FILES)){
				print_r($_FILES);
				move_uploaded_file($_FILES['hinhanh']['tmp_name'], 'public/upload/'.$_FILES['hinhanh']['name']);
				$HinhAnh = 'upload/'.$_FILES['hinhanh']['name'];
			}
			$obmh->addMatHang($_POST['cmb_choice'], $_POST['tenmh'], $_POST['dvt'], $_POST['soluong'], $_POST['gia'], $HinhAnh , $_POST['mota']);
			echo '<script> window.location.href="admin.php?mod=mathang"</script>';
		}
		$data['list'] = $oblh->listloaihang(); //lay danh sach loai hang
		require 'views/admin/mathang/add.php';
		break;
	}
	case 'delmathang':{
		$obmh->delMatHang($_GET['ma']);
		echo '<script> window.location.href="admin.php?mod=mathang"</script>';
		break;
	}

	case 'updatemathang':{
		if($_POST){
			$obmh->updateMatHang($_POST['cmb_choice'], $_POST['tenmh'], $_POST['dvt'], $_POST['soluong'], $_GET['ma']);
			echo '<script>window.location.href="admin.php?mod=mathang"</script>';
		}
		$data = $obmh->getMatHang($_GET['ma']);
		$data['listlh'] = $oblh->listloaihang();
		require 'views/admin/mathang/edit.php';
		break;
	}
	default: echo 'yeu cau chua duoc xu ly !'; break;
}
?>